-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Fix #19294, Ruby NetHttpRequest improvements #20101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
* | ||
* # connection re-use | ||
* Net::HTTP.start("http://example.com") do |http| | ||
* http.get("/") | ||
* end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that technically Net::HTTP.new
does not open/reuse connections/sessions: https://docs.ruby-lang.org/en/master/Net/HTTP.html#method-c-new
http = Net::HTTP.new("https://example.com") | ||
root_get = Net::HTTP::Get.new("/") | ||
http.request(root_get) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This case was already detected without the above code modifications, but I wanted to make sure that request objects are also detected correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for your contribution; changes look good to me, only minor changes needed.
@@ -12,15 +12,22 @@ private import codeql.ruby.DataFlow | |||
/** | |||
* A `Net::HTTP` call which initiates an HTTP request. | |||
* ```ruby | |||
* # one-off request |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file needs to be auto-formatted, using codeql query format --in-place NetHttp.qll
.
@@ -30,20 +37,27 @@ class NetHttpRequest extends Http::Client::Request::Range instanceof DataFlow::C | |||
| | |||
// Net::HTTP.get(...) | |||
method in ["get", "get_response"] and | |||
requestNode = API::getTopLevelMember("Net").getMember("HTTP").getReturn(method) and | |||
connectionNode = API::getTopLevelMember("Net").getMember("HTTP") and | |||
requestNode = connectionNode.getReturn(method) and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can move requestNode = connectionNode.getReturn(method)
up after line 36, and then remove the three duplicated lines.
This PR makes 3 improvements to the
NetHttpRequest
class:connectionNode
like other Ruby HTTP clients (see Ruby NetHttpRequest improvements #19294)requestNode
andconnectionNode
public so subclasses can use them (see Ruby NetHttpRequest improvements #19294)Net::HTTP.start
- this is a common way to make HTTP requests in Ruby